﻿using System;
using RenewalProjects.Libraries.Wcf.EasyProxy.Pools;

namespace RenewalProjects.Libraries.Wcf.EasyProxy.Tests.TestData
{
	public class TestItem : IResourceItem
	{
		private volatile bool _inUse;
		private string _id = Guid.NewGuid().ToString();

		public bool Expired { get; set; }
		public int DrainCalls { get; private set; }
		public int ExpiryCalls { get; private set; }

		public bool InUse
		{
			get { return _inUse; }
			set { _inUse = value; }
		}

		public bool CheckItemExpiry()
		{
			ExpiryCalls++;
			return Expired;
		}

		public void DrainItem()
		{
			DrainCalls++;
		}

		#region Equals and GetHashCode implementation

		public override bool Equals(object obj)
		{
			if(ReferenceEquals(this, obj))
			{
				return true;
			}

			TestItem other = obj as TestItem;
			if (other == null)
			{
				return false;
			}

			return this._id == other._id;
		}

		public override int GetHashCode()
		{
			return _id.GetHashCode();
		}

		#endregion
	}
}